package com.challenge.sewercoverbackend.api;

import com.challenge.sewercoverbackend.domian.Cover;
import com.challenge.sewercoverbackend.domian.CoverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 24270
 * @author 25835
 */
@CrossOrigin("*") // 后面不要加'/'会被拦截

@RestController
public class CoverRestController {
    @Autowired
    public CoverService service;

    /**
     * 写api的地方
     * TODO 接口待补充
     * 我老懒狗了
     */
    @GetMapping("/getAll")
    public List<Cover> getAll() {
        return service.getAll();
    }

    @GetMapping("/getCount")
    public int getCount(String tablename) {
        return service.getCount(tablename);
    }

    @GetMapping("/getLatestOne")
    public Cover getLatestOne(String tablename) {
        return service.getLatestOne(tablename);
    }

    @GetMapping("/getLatestTwenty")
    public List<Cover> getLatestTwenty() {
        return service.getLatestTwenty();
    }

    /**
     * 测试方法，测试查询CH4浓度为t的数据
     *
     * @param t
     * @return
     */
    @GetMapping("/getCH4/{t}")
    public List<Cover> getCH4(@PathVariable int t) {
        return service.getByCH4(t);
    }

    /**
     * 平均CH4
     * 输入参数：tablename
     */

    @GetMapping("/getAvgCH4")
    public double getAvgCH4(String tablename) {
        return service.getAvgCH4(tablename);
    }

    //平均CO
    @GetMapping("/getAvgCO")
    public double getAvgCO(String tablename) {
        return service.getAvgCO(tablename);
    }

    //按日期查询Cover
    @GetMapping("/getCoverByTime/{timeSelect}")
    public List<Cover> getCoverByTime(@PathVariable String timeSelect) {
        return service.getCoverByTime(timeSelect);
    }

    //按日期范围查询 值得注意的是范围是    前闭后开  区间
    @GetMapping("/getCoverByTwoTime")
    public List<Cover> getCoverByTwoTime(String tablename, String begintime, String endtime) {
        return service.getCoverByTwoTime(tablename, begintime, endtime);
    }

    //查询指定数目的数据条数
    @GetMapping("/getLatestByNum/{tablename}/{number}")
    public List<Cover> getLatestByNum(@PathVariable int number, @PathVariable String tablename) {
        return service.getLatestByNum(tablename, number);
    }

    /**
     * 查询最新n条CO
     */
    @GetMapping("/getCOByNum")
    public List<Integer> getCOByNum(String tablename, int number) {
        return service.getCOByNum(tablename, number);
    }

    /**
     * 查询指定表格n条CH4
     *
     * @param tablename 表名
     * @param number    数据条数
     * @return
     */
    @GetMapping("/getCH4ByNum")
    public List<Integer> getCH4ByNum(String tablename, int number) {
        return service.getCH4ByNum(tablename, number);
    }

    /**
     * 获取当前电量
     */
    @GetMapping("/getElectricity")
    public int getElectricity(String tablename) {
        return service.getElectricity(tablename);
    }

    /**
     *{tablename}
     * 两种传参方式混合使用
     */
    @GetMapping("/getTestDouble/{tablename}")
    public int getTestDouble(@PathVariable String tablename, int number) {
        return service.getTestDouble(tablename,number);
    }
}
